package com.unicloud.medical.oss.client;

import com.unicloud.medical.oss.client.selector.OssNameSelector;
import com.unicloud.medical.oss.common.ExtEndpoint;
import com.unicloud.medical.oss.common.model.BucketInfo;
import com.unicloud.medical.oss.common.model.DownloadObject;
import com.unicloud.medical.oss.common.model.ObjectInfo;
import com.unicloud.medical.oss.common.model.request.*;
import com.unicloud.medical.oss.common.util.FileUtil;
import com.unisound.medical.common.model.dto.ResultDTO;
import org.springframework.http.ResponseEntity;

import java.util.List;

public class OSSNameSelectorClient implements ExtEndpoint {
    private final ExtEndpoint extEndpoint;

    public OSSNameSelectorClient(ExtEndpoint extEndpoint) {
        this.extEndpoint = extEndpoint;
    }

    /**
     * 查看存储桶是否存在
     */
    public ResultDTO<Boolean> bucketExist(BucketExistRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.bucketExist(request);
    }

    /**
     * 创建存储桶
     */

    public ResultDTO<Boolean> createBucket(CreateBucketRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.createBucket(request);
    }

    /**
     * 创建默认权限存储桶(默认策略支持浏览器直接访问url)
     */
    public ResultDTO<Boolean> createDefaultPolicyBucket(CreateBucketRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.createDefaultPolicyBucket(request);
    }

    /**
     * 删除存储桶
     */
    public ResultDTO<Boolean> removeBucket(DeleteBucketRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.removeBucket(request);
    }

    /**
     * 获取全部存储桶
     */
    public ResultDTO<List<BucketInfo>> getAllBuckets(CommonRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.getAllBuckets(request);
    }

    /**
     * 获取当前存储桶所有文件
     */
    public ResultDTO<List<ObjectInfo>> listAllObjectsCurrBucket(ListAllObjectsCurrBucketRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.listAllObjectsCurrBucket(request);
    }

    /**
     * 获取当前存储桶当前文件夹所有文件
     */
    public ResultDTO<List<ObjectInfo>> listObjectsCurrBucketAndFolder(ListAllObjectsCurrBucketAndFolderRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.listObjectsCurrBucketAndFolder(request);
    }

    /**
     * 文件上传
     */
    public ResultDTO<List<String>> uploadObjects(UploadObjectsRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.uploadObjects(request);
    }

    /**
     * 文件上传
     */
    public ResultDTO<String> uploadObject(UploadObjectRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.uploadObject(request);
    }

    /**
     * 本地文件上传
     */
    public ResultDTO<String> uploadLocalObject(UploadLocalObjectRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.uploadLocalObject(request);
    }

    /**
     * 批量上传本地文件
     */
    public ResultDTO<List<String>> uploadLocalObjects(UploadLocalObjectsRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.uploadLocalObjects(request);
    }

    /**
     * 文件下载
     */
    public ResponseEntity<byte[]> downloadObject(DownloadObjectRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return FileUtil.download(extEndpoint.downloadObject(request).getData());
    }


    /**
     * 下载文件夹下所有文件
     */
    public ResponseEntity<byte[]> downloadObjects(DownloadObjectsRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return FileUtil.download(extEndpoint.downloadObjects(request).getData());
    }


    /**
     * 根据url地址删除文件
     */
    public ResultDTO<String> removeObject(RemoveObjectRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.removeObject(request);
    }

    /**
     * 根据url地址列表批量删除文件
     */
    public ResultDTO<List<String>> removeObjects(RemoveObjectsRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.removeObjects(request);
    }

    /**
     * 删除当前桶当前文件夹所有文件
     */
    public ResultDTO<List<String>> removeObjects(RemoveObjectsCurrBucketAndFolderRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.removeObjects(request);
    }

    /**
     * 文件复制
     */
    public ResultDTO<String> copyObject(CopyObjectRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.copyObject(request);
    }

    /**
     * 已签名地址
     */
    public ResultDTO<String> signedUrl(SignedUrlRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.signedUrl(request);
    }

    /**
     * 批量已签名地址
     */
    public ResultDTO<List<String>> signedUrls(SignedUrlsRequest request, OssNameSelector ossNameSelector) {
        request.setOssName(ossNameSelector.select());
        return extEndpoint.signedUrls(request);
    }

    @Override
    public ResultDTO<Boolean> bucketExist(BucketExistRequest request) {
        return extEndpoint.bucketExist(request);
    }

    @Override
    public ResultDTO<Boolean> createBucket(CreateBucketRequest request) {
        return extEndpoint.createBucket(request);
    }

    @Override
    public ResultDTO<Boolean> createDefaultPolicyBucket(CreateBucketRequest request) {
        return extEndpoint.createDefaultPolicyBucket(request);
    }

    @Override
    public ResultDTO<Boolean> removeBucket(DeleteBucketRequest request) {
        return extEndpoint.removeBucket(request);
    }

    @Override
    public ResultDTO<List<BucketInfo>> getAllBuckets(CommonRequest request) {
        return extEndpoint.getAllBuckets(request);
    }

    @Override
    public ResultDTO<List<ObjectInfo>> listAllObjectsCurrBucket(ListAllObjectsCurrBucketRequest request) {
        return extEndpoint.listAllObjectsCurrBucket(request);
    }

    @Override
    public ResultDTO<List<ObjectInfo>> listObjectsCurrBucketAndFolder(ListAllObjectsCurrBucketAndFolderRequest request) {
        return extEndpoint.listObjectsCurrBucketAndFolder(request);
    }

    @Override
    public ResultDTO<String> uploadObject(InnerUploadObjectRequest request) {
        return null;
    }

    @Override
    public ResultDTO<List<String>> uploadObjects(InnerUploadObjectsRequest request) {
        return null;
    }

    @Override
    public ResultDTO<List<String>> uploadObjects(UploadObjectsRequest request) {
        return extEndpoint.uploadObjects(request);
    }

    @Override
    public ResultDTO<String> uploadObject(UploadObjectRequest request) {
        return extEndpoint.uploadObject(request);
    }

    @Override
    public ResultDTO<String> uploadLocalObject(UploadLocalObjectRequest request) {
        return extEndpoint.uploadLocalObject(request);
    }

    @Override
    public ResultDTO<List<String>> uploadLocalObjects(UploadLocalObjectsRequest request) {
        return extEndpoint.uploadLocalObjects(request);
    }

    @Override
    public ResponseEntity<byte[]> downloadObjectToBrowser(DownloadObjectRequest request) {
        return extEndpoint.downloadObjectToBrowser(request);
    }

    @Override
    public ResultDTO<DownloadObject> downloadObject(DownloadObjectRequest request) {
        return extEndpoint.downloadObject(request);
    }

    @Override
    public ResultDTO<DownloadObject> downloadObjects(DownloadObjectsRequest request) {
        return extEndpoint.downloadObjects(request);
    }

    @Override
    public ResponseEntity<byte[]> downloadObjectsToBrowser(DownloadObjectsRequest request) {
        return extEndpoint.downloadObjectsToBrowser(request);
    }

    @Override
    public ResultDTO<String> removeObject(RemoveObjectRequest request) {
        return extEndpoint.removeObject(request);
    }

    @Override
    public ResultDTO<List<String>> removeObjects(RemoveObjectsRequest request) {
        return extEndpoint.removeObjects(request);
    }

    @Override
    public ResultDTO<List<String>> removeObjects(RemoveObjectsCurrBucketAndFolderRequest request) {
        return extEndpoint.removeObjects(request);
    }

    @Override
    public ResultDTO<String> copyObject(CopyObjectRequest request) {
        return extEndpoint.copyObject(request);
    }

    @Override
    public ResultDTO<String> signedUrl(SignedUrlRequest request) {
        return extEndpoint.signedUrl(request);
    }

    @Override
    public ResultDTO<List<String>> signedUrls(SignedUrlsRequest request) {
        return extEndpoint.signedUrls(request);
    }

}
